The members of HHS Programming Club were at a Brawl tournament and decided the tournament was not only a great opportunity to educate themselves on how to lose at Super Smash Brothers to Siraj, but also an opportunity to educate their minds by solving one on his great challenge problems. The problem is as follows:
Given an arithmetic progression of N numbers where the terms are A1, A2, A3, till AN. Determine how many to choose three numbers such that they are three consecutive terms of an arithmetic progression. (3,4,5) and (24,22,20) are examples of terms in an arithmetic progression while (2,7,11) and (3,7,5) are not.
Given an arithmetic progression of N numbers where the terms are A1, A2, A3, till AN. Determine how many to choose three numbers such that they are three consecutive terms of an arithmetic progression. (3,4,5) and (24,22,20) are examples of terms in an arithmetic progression while (2,7,11) and (3,7,5) are not.
Input Format
First line of the input is the integer N. Then the following line contains N integers A1, A2, …, AN separated by spaces.
Sample Input
10
3 5 3 6 3 4 10 4 5 2
Output Format Output the number of ways to choose a triplet such that they are three consecutive terms of an arithmetic progression.
Sample Output
9
EXPLANATION: (1, 3, 5), (1, 6, 9), (1, 8, 9), (3, 6, 9), (3, 8, 9), (4, 6, 10),(4, 8, 10),(5, 6, 9), (5, 8, 9)
You must be logged in to submit a solution.